<template>
	<view class="page">
		<!-- 标题栏 start -->
		<fu-custom :isBack="true" bgColor="bg-white" class="header" :isBottom="true">
			<block slot="content">注销账号</block>
			<block slot="right">
			</block>
		</fu-custom>
		<view class="flex flex-direction margin solid-bottom padding-bottom">
			<view class="flex align-center">
				<image class="cancel-img margin-right-sm" src="../../static/account-cancel.png" mode=""></image>
				<text class="text-bold text-lg">账号注销</text>
			</view>
			<view class="margin-top">
				永久注销且无法恢复，请谨慎操作
			</view>
		</view>
		<view class="flex flex-direction margin solid-bottom padding-bottom">
			<view class="flex align-center">
				<text class="text-bold text-lg">账号注销后将放弃以下权益：</text>
			</view>
			<view class="margin-top" v-html="content">
			</view>
		</view>
		<view class="warning margin text-sm">
			点击下方按钮，即表示你已阅读并了解以上风险
		</view>
		<view class="login-btn" @click="showTip">
			我已清楚风险，确定继续
		</view>
		<view class="login-btn back" @click="cancel">
			返回
		</view>
		<!-- 断网监测 start -->
		<fu-notwork></fu-notwork>
		<!-- 断网监测 end -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cancelReason: '',
				cancelId: '',
				content:''
			}
		},
		onLoad(option) {
			this.cancelReason = option.cancelReason
			this.cancelId = option.cancelId
			this.get_column_article_list();
		},
		methods: {
			get_column_article_list(id) {
				this.$api.post(global.apiUrls.get_article_detail, {
					category_id: 47
				}).then(res => {
					console.log(res);
					if (res.data.code == 1) {
						this.content = res.data.data.content
					}
				}).catch(err => {
					console.log(err);
				})
			},
			cancel() {
				uni.navigateBack({
					delta: 2
				})
			},
			showTip() {
				let _this = this;
				this.$util.showModal({
					title: '提示',
					content: '请再次确认，你已了解注销风险,并要继续执行该操作',
					confirmColor: _this.$store.state.themeColor,
					success: res => {
						if (res.confirm) {
							_this.handleNext();
						}
					}
				});
			},
			handleNext() {
				uni.showLoading({
					title: '请稍等'
				});
				setTimeout(() => {
					this.$api.post(global.apiUrls.cancelAccountSub, {
						id: this.cancelId,
						cancelReason: this.cancelReason
					}).then(res => {
						uni.hideLoading();
						if (res.data.code == 1) {
							console.log(res.data)
							var cancelList = [...res.data.data.express, ...res.data.data.not_receive, ...
								res.data.data
								.not_yet_shipped
							]
							console.log(cancelList)
							// this.$store.commit('getCancelAccount', cancelList);
							// 注销失败
							uni.redirectTo({
								url: '/pages/index/setting/result/index?isSuccess=1&text='+this.cancelReason
							})
						} else if (res.data.code == 2) {
							//  注销成功
							// this.$store.commit('logout');
							uni.redirectTo({
								url: '/pages/index/setting/result/index?isSuccess=1&text='+this.cancelReason
							})
						} else {
							//  其他情况错误码
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
						}
					})
				}, 500)
			}
		},
	}
</script>
<style>
	page {
		height: 100%;
		background: #ffffff;
	}
</style>

<style lang="scss" scoped>
	page {
		height: 100%;
		background: #ffffff;
	}

	.cancel-img {
		width: 34rpx;
		height: 36rpx;
	}

	.content {
		min-height: 800rpx;
	}

	.agreement {
		display: flex;
		width: 100%;
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		color: #666666;
		align-items: center;
		justify-content: center;
		margin-bottom: 30rpx;

		.image {
			height: 28rpx;
			width: 28rpx;
			margin-right: 12rpx;
		}

		text {
			color: #FFA133;
		}
	}

	.login-btn {
		height: 88rpx;
		line-height: 88rpx;
		background: #FC9C3A;
		opacity: 1;
		border-radius: 44rpx;
		font-size: 32rpx;
		color: #FFFFFF;
		font-family: PingFang SC;
		font-weight: 500;
		text-align: center;
		position: fixed;
		bottom: 160rpx;
		left: 32rpx;
		right: 32rpx;
	}

	.back {
		bottom: 40rpx;
		background-color: #FFFFFF;
		border: 1rpx solid #FC9C3A;
		color: #FC9C3A;
	}

	.checkbox-list {
		padding: 20rpx 15rpx;
	}

	.item {
		padding-bottom: 32rpx;

		.item-img {
			width: 32rpx;
			height: 32rpx;
		}

		.item-label {
			margin-left: 10rpx;
		}
	}

	.warning {
		color: #FB2A25;
	}
</style>
